<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<html>
<head>
	<title>部门管理</title>
	<script src="${ctx}/static/detailPopover/areaGroupDetail.js" type="text/javascript"></script>
	<script>
		var datatable_content;
		$(function(){
			initTable();
		});
		
		function initTable(){
			datatable_content = $("#contentTable").dataTable({
			   "bServerSide":true,
	           "sAjaxSource":'${ctx}/department/page',
	           "fnServerData": callback,
	           "bFilter": false,
	           "bSort": false,
	           "sZeroRecords": "查询无记录！",
	           "bProcessing": true,
	           "oLanguage": {
	               "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
	            },
	             "aoColumns":[
	             	 {"mData": null},
	             	 {"mData": "deptintro"},
	             	 {"mData": null},
	             	 {"mData": "address"},
	             	 {"mData": "department.deptname"},
	             	 {"mData": null},
	             ],
	             "aoColumnDefs":[
	             	{"aTargets": [0],
		              "mRender": function (data, display, row) {
			        	 return "<a href=\"${ctx}/department/v2_update/"+row.id+"\">"+row.deptname+"</a>";
			           }
		            },
	             	{"aTargets": [2],
		              "mRender": function (data, display, row) {
			        	 return "<a href=\"#areaGroupDetail\" onclick=\"areaGroupDetailAjax('"+row.areaGroup.id+"','${ctx}')\" data-toggle=\"modal\">"+row.areaGroup.groupName+"</a>";
			           }
		            },
	             	{"aTargets": [5],
		              "mRender": function (data, display, row) {
			        	 return "<a class=\"btn btn-danger\" href=\"${ctx}/department/delete/"+row.id+"\">删除</a>";
			           }
		            },
	             ],
			});
		}
		
		function callback( sSource, aoData, fnCallback ) {
		 aoData.push( { "name": "search_LIKE_deptname", "value": $("#search_LIKE_deptname").val()});  
			 //查询参数
		   $.ajax({ 
		       "type": "post",
		       "contentType": "application/json", 
		       "url": sSource,    
		       "dataType": "json",   
		       "data": JSON.stringify(aoData),
		       "success": fnCallback  
		   });    
		}
		
		function query(){
			datatable_content.fnDestroy();
			initTable();
		}
	</script>
</head>

<body>
<section class="content">
		<c:if test="${not empty message}">
			<div id="message" class="alert alert-success"><button data-dismiss="alert" class="close">×</button>${message}</div>
		</c:if>
		<div class="row">
			<div class="col-md-12">
			<div class="box box-solid box-primary">
			<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
			<form class="form-search" action="#">
			 	<label>部门名：</label> <input type="text" name="search_LIKE_deptname" id="search_LIKE_deptname" class="input-medium" value="${param.search_LIKE_deptname}" onkeydown='if(event.keyCode==13) {query(); return false;}'> 
			    <button type="button" class="btn btn-info" onclick="query()">Search</button>
			    <a class="btn btn-info" href="${ctx}/department/v2_create">创建部门</a>
		    </form>
	    </div>
	</div>
	</div>
	</div>
	
	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-primary">
				<div class="box-header"></div>
				<div class="box-body">	
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>部门名</th>
				<th>部门介绍</th>
				<th>所属片区
				</th>
				<th>地址</th>
				<th>所属部门
				</th>
				<th>管理</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
	
</div>
</div>
</div>
</div>	
	<div id="areaGroupDetail"  class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" role="dialog">
		<div class="modal-dialog" style="width: 60%;">
		<div class="modal-content">
		<div class="modal-header">
			<h3>网点详情</h3>
		</div>
		<div class="modal-body">
			<table id="areaGroupDetailBody" class="table table-striped table-bordered table-condensed"></table>
		</div>
		<div class="modal-footer">
			<button class="btn" data-dismiss="modal" aria-hidden="true">返回</button>
		</div>
		</div>
		</div>
	</div>
	</section>
</body>
</html>
